/*
 * @Author: ZhanXie
 * @Date: 2020-09-06 11:50:41
 * @LastEditors: ZhanXie
 * @LastEditTime: 2020-09-06 16:13:15
 * @Description: 广场页 controller
 * @FilePath: /weibo/src/controller/blog-square.js
 */

const { getSquareCacheList } = require('../cache/blog')
const { PAGE_SIZE } = require('../conf/const')
const { SuccessModel } = require('../model/ResModel')

/**
 * 获取广场的微博列表
 * @param {number} pageIndex pageIndex
 */
async function getSquareBlogList(pageIndex = 0) {
  const result = await getSquareCacheList(pageIndex, PAGE_SIZE)
  const blogList = result.blogList

  // 拼接返回数据
  return new SuccessModel({
    isEmpty: blogList.length === 0,
    blogList,
    pageSize: PAGE_SIZE,
    pageIndex,
    count: result.count
  })
}

module.exports = {
  getSquareBlogList
}